package hn.cch.redis_token.controller;

import hn.cch.redis_token.message.TokenRequest;
import hn.cch.redis_token.message.TokenResponse;
import hn.cch.redis_token.service.RedisService;
import hn.cch.redis_token.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 登陆接口：客户端获取token
 */

@Api(tags = "登陆接口")
@Controller
public class LoginController {

    private static Logger logger = LoggerFactory.getLogger(LoginController.class);


    @Autowired
    private TokenService tokenService;

    @ApiOperation(value = "客户端获取token",notes = "服务端将token保存在redis中",httpMethod = "POST")
    // @PostMapping(value = "/login")
    @RequestMapping(value="/login", method= RequestMethod.GET)
    @ResponseBody
    // public @ResponseBody TokenResponse login(@RequestBody TokenRequest tokenRequest){
    public TokenResponse login(){
        logger.info("login");
        String token = tokenService.createToken();
        logger.info("token:{}", token);
        TokenResponse tokenResponse = TokenResponse.success();
        tokenResponse.setData(token);
        return tokenResponse;
    }

}
